package com.kintreda.ieco_server.module.attention.service.impl;

import com.kintreda.ieco_server.bean.account.User;
import com.kintreda.ieco_server.bean.attention.Attention;
import com.kintreda.ieco_server.core.repository.IBaseRepository;
import com.kintreda.ieco_server.core.service.impl.BaseServiceImpl;
import com.kintreda.ieco_server.module.account.service.IUserService;
import com.kintreda.ieco_server.module.attention.service.IAttentionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @Created by IntelliJ IDEA
 * @Project_Name ieco_server
 * @Package com.kintreda.ieco_server.module.attention.service.impl
 * @Author ZhongYao_H
 * @Date 2019/4/29:14:53
 * @Year 2019 Month 04 Day 29
 * @Date_zh 2019 年 四月 星期一
 */
@Service
public class AttentionServiceImpl extends BaseServiceImpl<Attention,String> implements IAttentionService {
    @Autowired
    IBaseRepository<Attention,String> attentionStringIBaseRepository;
    @Autowired
    IUserService userService;

    @Override
    public List<Attention> getFocusOrg(String userogId) {
        return query("from Attention where userId = ? " ,new Object[]{userogId});
    }

    @Override
    public Boolean isFocus(String userId, String OrgId) {
        List<Attention> query = query("from Attention where userId = ? and orgId = ?", new Object[]{userId, OrgId});
        return query.size()>0?true:false;
    }

    @Override
    public List<Attention> getListByOrgId(String orgId) {
        return query("from Attention where orgId = ? " ,new Object[]{orgId});
    }


    @Override
    public List<Map<String, Object>> getFocusUser(String orgId) {
        List<Map<String, Object>> list = attentionStringIBaseRepository.findListBySql("select openId from attention where orgId =  ?", new Object[]{orgId});
        for (Map<String, Object> map : list) {
            User user = userService.findUserByOpenId(map.get("openId").toString());
            if (user != null) {
                map.put("name",user.getName());
            }
        }
        return list;

    }
}
